using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Net.Fan.SmallPig.Common.DrawOperate
{
    public class ItemRectangle
    {
        int y, higth, x, width;

        public int Width
        {
            get { return width; }
            set { width = value; }
        }

        public int X
        {
            get { return x; }
            set { x = value; }
        }

        public int Heigh
        {
            get { return higth; }
            set { higth = value; }
        }

        public int Y
        {
            get { return y; }
            set { y = value; }
        }

        public int Right
        {
            get
            {
                return x + width;
            }
        }

        public int Bottom
        {
            get
            {
                return y + higth;
            }
        }

        public Point TopCenter()
        {
            Point p = new Point((x + Width / 2), y);
            return p;
        }

        public Point BottomCenter()
        {
            Point p = new Point((x + Width / 2), Bottom);
            return p;
        }

        public Point RightCenter()
        {
            Point p = new Point(Right, y + higth / 2);
            return p;
        }

        public Point LeftCenter()
        {
            Point p = new Point(x, y + higth / 2);
            return p;
        }

        public Direction GetDirection(ItemRectangle b)
        {
            if (this.x > b.x)
            {
                //b in top
                if (this.y > b.y)
                {
                    return Direction.TopLeft;
                }
                else
                {
                    return Direction.TopRight;
                }

            }
            else
            {
                if (this.y > b.y)
                {
                    return Direction.BottomLeft;
                }
                else
                {
                    return Direction.BottomRight;
                }
            }

        }

    }

    public enum Direction
    {
        Top, TopRight, TopLeft, Right, BottomRight, Bottom, BottomLeft, Left
    }
}
